package com.ruoyi.paint.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paint.domain.TqCars;
import com.ruoyi.paint.service.ITqCarsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车信息Controller
 * 
 * @author itchen
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/paint/cars")
public class TqCarsController extends BaseController
{
    @Autowired
    private ITqCarsService tqCarsService;

    /**
     * 查询汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:list')")
    @GetMapping("/list")
    public TableDataInfo list(TqCars tqCars)
    {
        startPage();
        List<TqCars> list = tqCarsService.selectTqCarsList(tqCars);
        return getDataTable(list);
    }

    /**
     * 导出汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:export')")
    @Log(title = "汽车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TqCars tqCars)
    {
        List<TqCars> list = tqCarsService.selectTqCarsList(tqCars);
        ExcelUtil<TqCars> util = new ExcelUtil<TqCars>(TqCars.class);
        util.exportExcel(response, list, "汽车信息数据");
    }

    /**
     * 获取汽车信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tqCarsService.selectTqCarsById(id));
    }

    /**
     * 新增汽车信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:add')")
    @Log(title = "汽车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TqCars tqCars)
    {
        return toAjax(tqCarsService.insertTqCars(tqCars));
    }

    /**
     * 修改汽车信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:edit')")
    @Log(title = "汽车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TqCars tqCars)
    {
        return toAjax(tqCarsService.updateTqCars(tqCars));
    }

    /**
     * 删除汽车信息
     */
    @PreAuthorize("@ss.hasPermi('paint:cars:remove')")
    @Log(title = "汽车信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tqCarsService.deleteTqCarsByIds(ids));
    }
}
